
package com.scs.application.modules.upms.controller;

import com.scs.application.core.exceptions.BusinessException;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.mvc.controller.BaseController;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.upms.entity.Shortcut;
import com.scs.application.modules.upms.request.ShortcutQueryRequest;
import com.scs.application.modules.upms.security.UserPrincipal;
import com.scs.application.modules.upms.service.ShortcutService;
import com.scs.application.modules.upms.vo.UserShortcutVo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 快捷方式 controller
 */
@AllArgsConstructor
@RestController
@RequestMapping("/upms/shortcuts")
public class ShortcutController extends BaseController {

    private final ShortcutService shortcutService;

    /**
     * @param menuIds
     * @Description: 批量保存收藏菜单
     * @return: scs.application.core.model.CommonResult
     */
    @PostMapping("/batch_save")
    public CommonResult batchSave(@RequestBody String[] menuIds) {
        BusinessException.throwError("该方法不可用");
        boolean bSave = shortcutService.batchSaveShortcut(menuIds);
        return bSave ? CommonResult.ok("保存成功") : CommonResult.error("保存失败");
    }

    /**
     * @Description: 批量保存收藏菜单
     * @return: scs.application.core.model.CommonResult
     */
    @PostMapping("/batchSaveMenu")
    public CommonResult batchSaveMenu(@RequestBody List<Shortcut> list) {
        return CommonResult.ok("保存成功", shortcutService.batchSaveMenu(list)) ;
    }


    @GetMapping("/list")
    public CommonResult list(ShortcutQueryRequest request) {
        UserPrincipal user = UserUtils.currentUser();
        request.setUserId(user.getId());
        List<UserShortcutVo> list = shortcutService.list(request);
        return CommonResult.ok("查询成功", list);
    }


}
